#include<iostream>
#include<set>
#include<unordered_map>
#include<cstring>
using namespace std;
const int N=1e5+10;
int n,m,k;
unordered_map<int,int> vis;
set<int> arr[55];
double find(int n,int m)
{
    vis.clear();
	int res=0,cnt=0;
	double ans=0;
	for(auto a:arr[n])
	vis[a]=1,cnt++;
	for(auto a:arr[m])
	{
		if(vis[a])
		res++;
		else
		cnt++;
	}
	ans=(double)res/cnt;
	return ans;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>m;
		for(int j=1;j<=m;j++)
		{
			int num;
			cin>>num;
			arr[i].insert(num);
		}
	}
	cin>>k;
	while(k--)
	{
		int u,v;
		cin>>u>>v;
		printf("%.2f%\n",100*find(u,v));
	}
	return 0;
}
